package com.controller;

import com.common.utils.ServletUtils;
import com.common.utils.StringUtils;
import com.generator.entity.Tree;
import com.system.service.SystemMenuService;
import com.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author yz
 * @data: 2022/4/2 20:49 星期六
 * @file : CommonController.java
 */

@Controller
public class CommonController {


    @Autowired
    private SystemMenuService systemMenuService;

    @RequestMapping("/index")
//    @RequiresPermissions("system:index:view")
    public String index(UserVO userVO, Model model) {
        model.addAttribute("name", userVO.getLoginName());
        return "index" ;
    }

    @GetMapping("/toLogin")
    public String toLogin(HttpServletRequest request, HttpServletResponse response) {
        if (ServletUtils.isAjaxRequest(request)) {
            return StringUtils.renderString(response, "{\"code\":\"1\",\"msg\":\"未登录或登录超时。请重新登录\"}");
        }
        return "login" ;
    }


    @RequestMapping("/test")
    public String test() {
        Tree tree = new Tree();
        System.out.println("tree = " + tree);
        return "test" ;
    }

//    @GetMapping("/data")
//    @ResponseBody
//    public List<Tree> data() {
////        List<Tree> t = systemMenuService.getTree();
//        System.out.println("t = " + t);
//        return t;
//    }


}
